<script src="../../gun.js"></script>
<script src="../../lib/cryptomodules.js"></script>
<script src="../../sea.js"></script>
<script>
;(function(){
	localStorage.clear();
	
	var gun = window.gun = Gun();
	var user = gun.user();

	user.create('alice', 'unsafepassword', login);

	function login(ack){
		console.log("login...");
		user.auth('alice', 'unsafepassword', keys);
	}

	function keys(data){
		console.log("keys...");
		const keys = user.pair();
		console.log(keys);
		Gun.SEA.keyid(keys.pub).then(function (keyid) {
			console.log("Public key KeyID (PGPv4): " + keyid);
			write(keys);
		});
	}

	function write(data){
		console.log("write...");
		var alice = {name: "Alice"};
		alice.boss = {name: "Fluffy", slave: alice};
		user.get('profile').put(alice, get);
	}

	function get(){
		console.log("get...");
		user.get('profile').get('boss').get('slave').get('name').val(function(data){
			console.log("The boss's slave's name is:", data);
		})
	}

}());
</script>